%option noyywrap
%{
#include "yacc.tab.h"

#define PRINT(fmt, ...) /* 空实现，不打印 */

%}

INTCON     [0-9]+
IDENFR     [a-zA-Z_][a-zA-Z0-9_]*
STRCON     \"([^\"\\]|\\.)*\" 

%%

"main"              { PRINT("MAINTK main\n"); return MAIN; }
"const"             { PRINT("CONSTTK const\n"); return CONST; }
"int"               { PRINT("INTTK int\n"); return INT; } 
"getint"            { PRINT("GETINTTK getint\n"); return GETINT; }
"printf"            { PRINT("PRINTFTK printf\n"); return PRINTF; }
"return"            { PRINT("RETURNTK return\n"); return RETURN; }
"while"             { PRINT("WHILETK while\n"); return WHILE; }
"if"                { PRINT("IFTK if\n"); return IF; }
"else"              { PRINT("ELSETK else\n"); return ELSE; }
"void"              { PRINT("VOIDTK void\n"); return VOID; }
"break"             { PRINT("BREAKTK break\n"); return BREAK; }
"continue"          { PRINT("CONTINUETK continue\n"); return CONTINUE; }

"="                 { PRINT("ASSIGN =\n"); return ASSIGN; }
"=="                { PRINT("EQL ==\n"); return EQL; }
"!="                { PRINT("NEQ !=\n"); return NEQ; }
"<"                 { PRINT("LSS <\n"); return LSS; }
"<="                { PRINT("LEQ <=\n"); return LEQ; }
">"                 { PRINT("GRE >\n"); return GRE; }
">="                { PRINT("GEQ >=\n"); return GEQ; }
"&&"                { PRINT("AND &&\n"); return AND; }
"||"                { PRINT("OR ||\n"); return OR; }
"!"                 { PRINT("NOT !\n"); return NOT; }
"+"                 { PRINT("PLUS +\n"); return PLUS; }
"-"                 { PRINT("MINU -\n"); return MINU; }
"*"                 { PRINT("MULT *\n"); return MULT; }
"/"                 { PRINT("DIV /\n"); return DIV; }
"%"                 { PRINT("MOD %%\n"); return MOD; }
"("                 { PRINT("LPARENT (\n"); return LPARENT; }
")"                 { PRINT("RPARENT )\n"); return RPARENT; }
"{"                 { PRINT("LBRACE {\n"); return LBRACE; }
"}"                 { PRINT("RBRACE }\n"); return RBRACE; }
"["                 { PRINT("LBRACK [\n"); return LBRACK; }
"]"                 { PRINT("RBRACK ]\n"); return RBRACK; }
";"                 { PRINT("SEMICN ;\n"); return SEMICN; }
","                 { PRINT("COMMA ,\n"); return COMMA; }

{INTCON}            { PRINT("INTCON %s\n",yytext); return INT_CONST;}
{IDENFR}            { PRINT("IDENFR %s\n",yytext); return IDENT;}
{STRCON}            { PRINT("STRCON %s\n", yytext); return STR_CONST;}

[ \t\r\n]+          ;   // 忽略空白符
.                   { PRINT("TOKEN: UNKNOWN (%s)\n", yytext); }
"//"[^"\n"]*       ;   // 跳过单行注释
%%
